package calao.test.plan;

import static org.junit.Assert.assertEquals;

import java.util.Calendar;

import calao.client.util.CalendarDate;
import calao.plan.client.WorkPeriod;

class Util 
{

	static long getTime(int year, int month, int day, int hour, int min)
	{
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month-1);
		cal.set(Calendar.DAY_OF_MONTH, day);
		cal.set(Calendar.HOUR_OF_DAY, hour);
		cal.set(Calendar.MINUTE, min);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		return cal.getTimeInMillis();
	}
	
	static void assertTime(long time, 
			int year, int month, int day, int hour, int min)
	{
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(time);
		assertEquals(year, cal.get(Calendar.YEAR));
		assertEquals(month, cal.get(Calendar.MONTH)+1);
		assertEquals(day, cal.get(Calendar.DAY_OF_MONTH));
		assertEquals(hour, cal.get(Calendar.HOUR_OF_DAY));
		assertEquals(min, cal.get(Calendar.MINUTE));
	}

	static WorkPeriod[] buildSampleWorktimes()
	{
		// 8:30-12:00 13:00-17:30 on monday to thursday
		// 8:30-12:00 13:00-16:00 on friday
		WorkPeriod[] wperiods = new WorkPeriod[10];
		wperiods[0] = newWorkPeriod(CalendarDate.MONDAY, 8, 30, 12, 0);
		wperiods[1] = newWorkPeriod(CalendarDate.MONDAY, 13, 0, 17, 30);
		wperiods[2] = newWorkPeriod(CalendarDate.TUESDAY, 8, 30, 12, 0);
		wperiods[3] = newWorkPeriod(CalendarDate.TUESDAY, 13, 0, 17, 30);
		wperiods[4] = newWorkPeriod(CalendarDate.WEDNESDAY, 8, 30, 12, 0);
		wperiods[5] = newWorkPeriod(CalendarDate.WEDNESDAY, 13, 0, 17, 30);
		wperiods[6] = newWorkPeriod(CalendarDate.THURSDAY, 8, 30, 12, 0);
		wperiods[7] = newWorkPeriod(CalendarDate.THURSDAY, 13, 0, 17, 30);
		wperiods[8] = newWorkPeriod(CalendarDate.FRIDAY, 8, 30, 12, 0);
		wperiods[9] = newWorkPeriod(CalendarDate.FRIDAY, 13, 0, 16, 0);
		return wperiods;		
	}
	
	static WorkPeriod newWorkPeriod(int day, int startHour, int startMin, 
			int endHour, int endMin)
	{
		WorkPeriod period = new WorkPeriod();
		period.setWeekDay(day);
		period.setStartHour(startHour);
		period.setStartMin(startMin);
		period.setEndHour(endHour);
		period.setEndMin(endMin);
		return period;
	}

}
